<template>
  <div v-if="!isDetails">
    <!-- 搜索工作栏 -->
    <ContentWrap>
      <Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams">
        <!-- 新增等操作按钮 -->
        <template #actionMore>
          <!-- <el-button
            type="primary"
            plain
            @click="openForm('create')"
            v-hasPermi="['pro:public-interest-litigation:create']"
          >
            <Icon icon="ep:plus" class="mr-5px" /> 新增
          </el-button> -->
        </template>
      </Search>
    </ContentWrap>

    <!-- 列表 -->
    <ContentWrap>
      <Table
        :columns="allSchemas.tableColumns"
        :data="tableObject.tableList"
        :loading="tableObject.loading"
        :pagination="{
          total: tableObject.total
        }"
        v-model:pageSize="tableObject.pageSize"
        v-model:currentPage="tableObject.currentPage"
      >
        <template #action="{ row }">
          <el-button link type="primary" @click="handleToDetails(row)"> 详情 </el-button>
          <el-button
            link
            type="danger"
            v-hasPermi="['pro:electronic-delivery:delete']"
            @click="handleDelete(row.id)"
          >
            <Icon icon="ep:delete" />
            删除
          </el-button>
        </template>
      </Table>
    </ContentWrap>
  </div>
  <!-- 详情 -->
  <DeliveryDetails v-else :currentRow="state.currentRow" @cancel="cancelPage" />
</template>
<script setup lang="ts" name="PublicInterestLitigation">
import { allSchemas } from './electronicDeliveryData'
import * as ElectronicDeliveryApi from '@/api/pro/electronicdelivery'
import DeliveryDetails from './DeliveryDetails.vue'

import { useUserStore } from '@/store/modules/user'
const userStore = useUserStore()
const router = useRouter() // 路由
// let getRole = userStore.user.nickname.includes('转派')
// tableObject：表格的属性对象，可获得分页大小、条数等属性
// tableMethods：表格的操作对象，可进行获得分页、删除记录等操作
// 详细可见：https://doc.iocoder.cn/vue3/crud-schema/
const { tableObject, tableMethods } = useTable({
  getListApi: ElectronicDeliveryApi.getElectronicDeliveryPage, // 分页接口
  delListApi: ElectronicDeliveryApi.deleteElectronicDelivery // 删除接口
  // defaultParams: {  userStore.user.id }
})
// 获得表格的各种操作

const { getList, setSearchParams } = tableMethods

const isDetails = ref(false)

const state = reactive({
  currentRow: {}
})

/** 删除按钮操作 */
const handleDelete = (id: number) => {
  tableMethods.delList(id, false)
}

function handleToDetails(row) {
  state.currentRow = row
  isDetails.value = true
}

function cancelPage() {
  isDetails.value = false
  getList()
}

/** 初始化 **/
onMounted(() => {
  getList()
})
</script>
